package aoi.retail_system.mapper;

import aoi.retail_system.model.Product;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;


public interface ProductMapper extends BaseMapper<Product> {
    //查询所有商品
    @Select("SELECT * FROM products")
    List<Product> selectList();
    //根据商品ID查询商品
    @Select("SELECT * FROM products WHERE id = #{id}")
    Product selectById(@Param("id") Long id);
    //添加商品
    @Insert("INSERT INTO products (id, name, price, stock, description) VALUES (#{id}, #{name}, #{price}, #{stock}, #{description})")
    int insert(@RequestBody Product product);
    //修改商品
    @Update("UPDATE products SET id = #{id}, name = #{name}, price = #{price}, stock = #{stock}, description = #{description} WHERE id = #{id}")
    int updateById(@RequestBody Product product);
    //删除商品
    @Delete("DELETE FROM products WHERE id = #{id}")
    void deleteById(@Param("id") Long id);
}
